<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .box{
            width: 200px;
            height: 200px;
            margin: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        var box=document.querySelector('.box');
        box.addEventListener('mousemove',function(e){
            // console.log(e.pageX);
            // console.log(e.pageY);
            // console.log(box.offsetLeft);
            // console.log(box.offsetTop);
            var x=e.pageX-this.offsetLeft;
            var y=e.pageY-this.offsetTop;
            this.innerHTML="x的坐标是:"+x+"y的坐标是"+y;
            // console.log();
        })
    </script>
</body>
</html>